import Message from './message'

import vue from 'vue'

const MsgClass = vue.extend(Message)
const instance = new MsgClass()

export default {
  name: 'Message',

  show(text, type, duration) {
    instance.$mount(document.createElement('div'))
    document.body.appendChild(instance.$el)
    instance.type = type
    instance.text = text
    instance.isShow = true
    setTimeout(() => {
      instance.isShow = false
    }, duration)
  },

  success(text, duration = 2000) {
    this.show(text, 'success', duration)
  },

  error(text, duration = 2000) {
    this.show(text, 'error', duration)
  }
}
